public class tabla {
 private int regcont;
 private int cols;
 private int rows;
 private String[][] tablax;
 private String[] colnames;
 private String[][] historial;
 private int[] contidx;
 private int cursor;
 public tabla(String[] colNames, int Rows){
  regcont=0;
  colnames=colNames;
  cols=colnames.length; 
  rows=Rows;
  tablax=new String[rows][cols];
  historial=new String[rows][1];
  contidx=new int[rows];
  tablax[0]=colnames;
  cursor=-1;
 }
 protected int getCont(){
  return regcont;
 }
 protected void addFila(String[] valores){
  regcont++;
  cursor++;
  tablax[regcont]=valores;
  contidx[regcont]=0;
  historial[regcont][contidx[regcont]]="";
 }
 
 /*public void updValue(String column,String nombre,String valor){
  int reg=searchRecord(column,nombre);
  int cindex=searchIndexColumn(column);
  tablax[reg][cindex]=valor;
  contidx[reg]=contidx[reg]+1;
  historial[reg][contidx[reg]]=valor;
 }*/

 public void updValue(int indice,String columna,String valor){
  int cindex=searchIndexColumn(columna);
  tablax[indice][cindex]=valor;
  //contidx[indice]=contidx[indice]+1;
  //historial[indice][contidx[indice]]=valor;
 }
 
 protected int searchRecord(String column,String value){
  int cindex=searchIndexColumn(column);
  int encontrado=-1;
  for(int y=1;y<=regcont;y++){
   if(tablax[y][cindex].equals(value)){
    encontrado=y;
   }
  }
  return encontrado; 
 }

protected String[] obtRecord(int indice){
 return tablax[indice];
}

 protected int searchIndexColumn(String columnName){
  int encontrado=0;
  for(int x=0;x<cols;x++){
   if(columnName.equals(colnames[x])){
    encontrado=x;
   }
  }
  return encontrado;
 }

 protected String[] posFiltro(int pos,String direccion,String columname,String valor){
  int indice=searchIndexColumn(columname);
  String[] encontrada=new String[cols];
  if(direccion.equals("arriba")==true){
   for(int x=pos;x>0;x--){
    if(tablax[x][indice].equals(valor)==true){
     cursor=x;
     for(int c=0;c<cols;c++){
      encontrada[c]=new String(tablax[x][c]);
     }
     break;
    }
   }
  }
  return encontrada;
 }

 protected int obtCursor(){
  return cursor;
 }
/* public static void main(String[] args) {
   String[] columnas={"tipo","variable","valor"};
   tabla tab=new tabla(columnas,100);
   String[] fila1={"uno","dos","tres"};
   tab.addFila(fila1);
   String fila2[]={"cuatro","cinco","seis"};
   tab.addFila(fila2);
   String dato="int x,n,r;String y;Var z;";
   String subdato=dato;
   String linea="";
   String vars="";
   while(subdato.indexOf(";")!=-1){
    linea=subdato.substring(0,subdato.indexOf(";")+1);
    vars=linea.substring(linea.indexOf(" ")+1,linea.indexOf(";"));
    if(linea.indexOf(",")==-1){
      System.out.println(vars);
    }
    else
    {
      while(vars.indexOf(",")!=-1){
       System.out.println(vars.substring(0,vars.indexOf(",")));
       vars=vars.substring(vars.indexOf(",")+1,vars.length());
      }
      System.out.println(vars);
    }
    subdato=subdato.substring(subdato.indexOf(";")+1,subdato.length());
    System.out.println(linea);
   }
   String tipodato=dato.substring(0,dato.indexOf(" "));
   String variable="";
   
   System.out.println(tipodato);
   System.out.println(tab.searchRecord("variable","cinco"));
 }*/
}
